Smalltalk current createPackage: 'Easnoth-Tests' properties: #{}!
TestCase subclass: #EasnothArrayTest
	instanceVariableNames: 'imageArray'
	package: 'Easnoth-Tests'!

!EasnothArrayTest methodsFor: 'testing'!

testAtIndex
	imageArray := #(#('1-1' '1-2' '1-3' '1-4') #('2-1' '2-2')).
	self assert: (imageArray atIndex: #(1 1)) = '1-1'.
	self assert: (imageArray atIndex: #(2 2)) = '2-2'.
!

testAtIndexPut
	imageArray := #(#('1-1' '1-2' '1-3' '1-4') #('2-1' '2-2')).
	imageArray atIndex: #(1 3) put: 'smth'.
	self assert: (imageArray atIndex: #(1 3)) = 'smth'.
!

testAtLibrary
	imageArray := #(#('1-1' '1-2' '1-3' '1-4') #('2-1' '2-2')).
	self assert: (imageArray atLibrary: 1) = #('1-1' '1-2' '1-3' '1-4').
!

testLoadingLibrary
	|lib dict|
	imageArray := (Array new: 1).
	dict := #('dirt.png' 'grass.png' 'road.png' 'savanna.png').
	lib := LibraryInfos new
			index: 1;
			path: 'ressources/images/tiles/';
			srcArray: dict;
			onload: [
				Transcript cr; show:  (imageArray atIndex: #(1 1)) src.
                                self assert: (imageArray atIndex: #(1 1)) src = 'http://localhost:4000/projects/easnoth/ressources/images/tiles/dirt.png'.
                                self assert: (imageArray atIndex: #(1 3)) src = 'http://localhost:4000/projects/easnoth/ressources/images/tiles/road.png'.
			].
	imageArray loadLibrary: lib.
! !

TestCase subclass: #EasnothTest
	instanceVariableNames: ''
	package: 'Easnoth-Tests'!

!EasnothTest methodsFor: 'testing-helper'!

emulateRessourceTest: aTest
	|image arr|

	image := <new Image()>.
	arr := (Array new: 1).
	arr at: 1 put: image.
	image at: 'onload' put: [Tile arrayImg: arr. aTest value].
	image at: 'src' put: 'specter.png'.
!

testBug
	self assert: true.
! !

EasnothTest subclass: #CellTest
	instanceVariableNames: ''
	package: 'Easnoth-Tests'!

!CellTest methodsFor: 'testing'!

testNew
	|cell cellArray coods|
	self emulateRessourceTest: [
                cellArray := #(#(1 1) #(1 1)).
                coods := #(5 12).
                cell := Cell newWithContext: 'aCtx' cellArray: cellArray coods: coods.
                self assert: cell x = 5.
                self assert: cell y = 12.
                self assert: cell tile class = Tile.
	].
! !

EasnothTest subclass: #MapTest
	instanceVariableNames: ''
	package: 'Easnoth-Tests'!

!MapTest methodsFor: 'testing'!

testNew
	|map|
	map := Map new.
	self assert: map canvas class = TagBrush.
!

testNewWithMapArray
	|map cell|
	
self emulateRessourceTest: [
	map := Map newWithMapArray: #(#(#(#(1 1)))).

	self assert: map width = 1.
	self assert: map height = 1.
	self assert: map mapX = 98.5.
	self assert: map mapY = 40.
	self assert: map cells size = 1.
	self assert: (map cells at: 1) size = 1.
	
	cell := (map cells at:1) at: 1.
	self assert: cell class = Cell.
	self assert: cell tile class = Tile.
].
! !

EasnothTest subclass: #TileTest
	instanceVariableNames: ''
	package: 'Easnoth-Tests'!

!TileTest methodsFor: 'testing'!

testNew
	|tile|
	self emulateRessourceTest: [
                tile := Tile newWithContext: 'aCtx' index: #(1 1).
                self assert: tile context = 'aCtx'.
		self assert: tile isWall = false.
	].
! !

EasnothTest subclass: #WorldTest
	instanceVariableNames: 'world'
	package: 'Easnoth-Tests'!

!WorldTest methodsFor: 'testing'!

testDisplay
	|image arr|
	image := <new Image()>.
	arr := (Array new: 1).
	arr at: 1 put: (Array new: 1).
	arr atIndex: #(1 1) put: image.
	image at: 'onload' put: [world := World newMapEditorWorldWithLibrairies: #(#(1 2 3 4) #(1 2 3 4)) map: 1. Tile arrayImg: arr. world startGame].
	image at: 'src' put: 'specter.png'.
	self assert: true.
!

testNew
	self emulateRessourceTest: [
		world := World newMapEditorWorldWithLibrairies: #(#(1 3 5) #(1 2 6)) map: 1.
		self assert: world map class = Map.
		self assert: world resource class = Resource.
		self assert: world eventManager class = MapEditorEventManager.
	].
! !

TestCase subclass: #LibraryInfosTest
	instanceVariableNames: 'imageArray'
	package: 'Easnoth-Tests'!

!LibraryInfosTest methodsFor: 'testing'!

testLoad
	|array libInfo|
	array := (Array new: 1).
	LibraryInfos new
			index: 1;
			path: 'ressources/images/tiles/';
			srcArray: #('road.png' 'dirt.png');
			onload: [
				Transcript cr; show: 'array : ',array.
				self assert: (array atIndex: #(1 1)) src = 'http://localhost:4000/projects/easnoth/ressources/images/tiles/road.png'.
                                self assert: (array atIndex: #(1 2)) src = 'http://localhost:4000/projects/easnoth/ressources/images/tiles/dirt.png'.
			];
			load: array.
! !

TestCase subclass: #Resourcetest
	instanceVariableNames: ''
	package: 'Easnoth-Tests'!

!Resourcetest methodsFor: 'testing'!

testNew
	|res|
	res := Resource new.
	self assert: Tile arrayImg = res tileImg.
	self assert: res tileImg class = Array.
!

testNewWith
	|res|
	res := Resource newWithLibrairies: #(#(1) #(1)) map: 1 world: (World new loaded: 0; totalToLoad: 2).
	self assert: (res tileImg atIndex: #(1 1)) src = 'http://localhost:4000/projects/easnoth/ressources/images/tiles/road.png'.
	"self assert: (res buildingImg atIndex: #(1 1)) src = 'http://localhost:4000/projects/easnoth/ressources/images/buildings/house.png'."
! !

TestCase subclass: #XMLHttpRequestProxyTest
	instanceVariableNames: ''
	package: 'Easnoth-Tests'!

!XMLHttpRequestProxyTest methodsFor: 'testing'!

testLoad
	|xmlProxy xmlDoc|
xmlProxy := XMLhttpRequestProxy new.
xmlDoc := xmlProxy loadXML: 'ressources/xml/maps/map1.xml'.
self assert: xmlDoc class = JSObjectProxy.
! !

